package com.ctrl.riveradministrator.mvp.presenter;

import android.util.Log;

import com.ctrl.riveradministrator.base.BaseObserver;
import com.ctrl.riveradministrator.base.BasePresenter;
import com.ctrl.riveradministrator.RaApplication;
import com.ctrl.riveradministrator.mvp.model.Reach;
import com.ctrl.riveradministrator.mvp.view.activity.trace.statistics.StatisticView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StatisticsPresenter extends BasePresenter<StatisticView> {

    public StatisticsPresenter(StatisticView baseView) {
        super(baseView);
    }

    public void getReach() {
        Map<String, String> map = new HashMap<>();
        map.put("userId", RaApplication.getUserId());
        attachView(apiService.getReach(map), new BaseObserver<Reach>(getBaseView()) {

            @Override
            public void onSuccess(Reach model) {

            }

            @Override
            public void onSuccess(List<Reach> model) {
                Log.d("cyc", "河流getReach: " + model);
                getBaseView().getReach(model);
            }

            @Override
            public void onFailed(String msg) {
                Log.d("cyc", "河流failed::" + msg);
                //getBaseView().onFailed(msg);
            }
        });
    }

    /**
     * 根据用户id查询用户的水库列表
     *
     * @param userId 用户ID
     */
    public void getReservoirList(String userId) {
        Map<String, String> map = new HashMap<>();
        map.put("userId", userId);
        attachView(apiService.getReservoirById(map), new BaseObserver<Reach>(getBaseView()) {
            @Override
            public void onSuccess(Reach model) {
                Log.d("onSuccess",":");
            }

            @Override
            public void onSuccess(List<Reach> model) {
                getBaseView().getReservoir(model);
            }

            @Override
            public void onFailed(String msg) {
                Log.d("onFailed",":"+msg);
            }

        });
    }

    /**
     * 根据水库id获取统计报告
     *
     * @param id 水库ID
     */
    public void getStatisticsList(String id) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        attachView(apiService.getStatisticsById(map), new BaseObserver<Reach>(getBaseView()) {
            @Override
            public void onSuccess(Reach model) {
                Log.d("onSuccess",":");
            }

            @Override
            public void onSuccess(List<Reach> model) {
                getBaseView().getStatistic(model);
            }

            @Override
            public void onFailed(String msg) {
                Log.d("onFailed",":"+msg);
            }

        });
    }

    /**
     * 根据河流id获取统计报告
     *
     * @param id 水库ID
     */
    public void getStatisticsRiverList(String id) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        attachView(apiService.getStatisticsRiverById(map), new BaseObserver<Reach>(getBaseView()) {
            @Override
            public void onSuccess(Reach model) {
                Log.d("onSuccess",":");
            }

            @Override
            public void onSuccess(List<Reach> model) {
                getBaseView().getStatistic(model);
            }

            @Override
            public void onFailed(String msg) {
                Log.d("onFailed",":"+msg);
            }

        });
    }
}
